export default {
	// 为当前模块开启命名空间
	namespaced: true,
	state: {
		// 用户收货地址
		userAddress: JSON.parse(uni.getStorageSync('userAddress') || '{}'),
		// 用户信息
		userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		// token
		token: JSON.parse(uni.getStorageSync('token') || 'null'),
		// 缓存之前跳转之前页面
		redirectInfo: {}
	},
	mutations: {
		setUserAddress(state, paly) {
			state.userAddress = paly
			uni.setStorageSync('userAddress', JSON.stringify(state.userAddress))
		},
		updateUserInfo(state, play) {
			state.userInfo = play
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
		},
		// token
		updateUserToken(state, play) {
			state.token = play
			uni.setStorageSync('token', JSON.stringify(state.token))
		},
		updateRedirectInfo(state, paly) {
			state.redirectInfo = paly
		} 
	},
	getters: {
		cartTotal(state) {
			let t = 0;
			state.cartList.forEach((x) => t += x.goods_count)
			return t
		},
		// 收货地址
		addstr(state) {
			if (!state.userAddress.provinceName) return ''

			return state.userAddress.provinceName + state.userAddress.cityName + state.userAddress.countyName + state
				.userAddress
				.detailInfo
		}
	}
}
